package com.ljx.recruit;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import okhttp3.Response;
import okhttp3.ResponseBody;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-06-02  22:50
 */
public class MainServer {

    public static void main(String[] args) throws IOException {
        List<Job> res = new ArrayList<>();

        for(int i = 1; i < 8; i++){
            int page = i * 90;
            Response response = HttpUtil.doGet("https://xiaoyuan.zhaopin.com/api/sou?S_SOU_FULL_INDEX=&S_SOU_POSITION_SOURCE_TYPE=&pageIndex=1&S_SOU_POSITION_TYPE=2&S_SOU_WORK_CITY=&S_SOU_JD_INDUSTRY_LEVEL=&S_SOU_COMPANY_TYPE=&S_SOU_REFRESH_DATE=&order=12&pageSize=" + page + "&_v=0.76780537&version=0.0.0&at=7714d56e912844aa976584a5201fbb90&rt=87f86ff399094e6c82aced8b5f9b46cf&S_SOU_JD_JOB_LEVEL=9000000000000%3B20000000000000&x-zp-page-request-id=1391faf485e5480d8aea702bc8908c5b-1717338729137-239125&x-zp-client-id=65c34157-666c-456d-85bf-c26be6442446");
            ResponseBody responseBody = response.body();
            JSONObject data = JSONUtil.parseObj(responseBody.string().toString());
            JSONObject childData = JSONUtil.parseObj(data.getStr("data"));
            JSONObject childDataData = JSONUtil.parseObj(childData.getStr("data"));
            List<Job> list = childDataData.getBeanList("list", Job.class);
            res.addAll(list);
        }
//        System.out.println(res.size());

        List<Job> ans = new ArrayList<>();
        for(int i = 0; i < res.size(); i += 3){
            ans.add(res.get(i));
        }
        handlerExcel(ans);

    }

    private static void handlerExcel(List<Job> res) {
        EasyExcel.write("xxx.xlsx", Job.class).sheet("Sheet1").doWrite(res);

//        HttpServletResponse response
//        EasyExcel.write(response.getOutputStream())
//                .head(Job.class)
//                .excelType(ExcelTypeEnum.XLSX)
//                .sheet("作业")
//                .doWrite(userList);
    }
}
